#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

//client
int main()
{
    int sockfd = socket(AF_INET,SOCK_DGRAM,0);
    if(sockfd < 0)
        std::cout << "socket error" << std::endl;
    while(true)
    {
        struct sockaddr_in server_addr;
        server_addr.sin_family = AF_INET;
        server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
        server_addr.sin_port = htons(8080);
        
        std::string msg = "hello world";
        int wn = sendto(sockfd,msg.c_str(),msg.size(),0,(struct sockaddr*)&server_addr,sizeof(server_addr));
        char buffer[1024] = {0};
        int rn = recvfrom(sockfd,buffer,sizeof(buffer),0,nullptr,nullptr);
        std::cout << buffer << std::endl;
    }    
    return 0;
}
